package org.example;

import org.apache.calcite.config.Lex;
import org.apache.calcite.sql.SqlDialect;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.ddl.MyTestDialect;
import org.apache.calcite.sql.parser.SqlParseException;
import org.apache.calcite.sql.parser.SqlParser;
import org.apache.calcite.sql.parser.ddl.SqlDdlParserImpl;
import org.apache.calcite.sql.util.SqlString;
import org.apache.calcite.sql.validate.SqlConformanceEnum;

// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
// then press Enter. You can now see whitespace characters in your code.
public class Main {
    public static void main(String[] args) throws SqlParseException {
//        String mysqlSql = "select * from persion where name !=='zhangsan' and id <10 limit 10 offset 4";
//        String mysqlSql = "insert into persion values(1,'zhangsan') ";
        String mysqlSql = "CREATE TABLE persion ( id INT  PRIMARY KEY,  name VARCHAR(255) ) ";
        SqlParser.Config config = SqlParser.config();
        config=config.withLex(Lex.MYSQL)
                .withParserFactory(SqlDdlParserImpl.FACTORY)
                .withConformance(SqlConformanceEnum.MYSQL_5);

        SqlParser parser = SqlParser.create(mysqlSql, config);
        SqlNode sqlNode = parser.parseStmt();
        System.out.println("mysql:  " + sqlNode);
        System.out.println("=============");
        SqlDialect dialect = MyTestDialect.DEFAULT;


        SqlString sqlString = sqlNode.toSqlString(dialect);
        System.out.println(sqlString.getSql());

    }
}